package com.zoo.diannaopeijian.service.impl;

import com.zoo.diannaopeijian.common.page.Page;
import com.zoo.diannaopeijian.common.util.CheckUtil;
import com.zoo.diannaopeijian.domain.Repertory;
import com.zoo.diannaopeijian.mapper.RepertoryMapper;
import com.zoo.diannaopeijian.service.RepertoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 仓库服务实现类
 */
@Service
public class RepertoryServiceImpl implements RepertoryService {
    @Resource
    private RepertoryMapper repertoryMapper;

    @Override
    public List<Repertory> getRepertory(Repertory repertory) {
        return repertoryMapper.select(repertory);
    }

    @Override
    public List<Repertory> getRepertoryWithPage(Page page, Repertory repertory) {
        if (page != null) {
            page.onPage();
        }

        return getRepertory(repertory);
    }

    @Override
    public List<Repertory> getFuzzyRepertory(Repertory repertory) {
        return repertoryMapper.selectFuzzyRepertory(repertory);
    }

    @Override
    public List<Repertory> getFuzzyRepertoryWithPage(Page page, Repertory repertory) {
        if (page != null) {
            page.onPage();
        }

        return getFuzzyRepertory(repertory);
    }

    @Override
    public boolean addRepertory(Repertory repertory) {
        if (CheckUtil.allNullBeanCheck(repertory)) {
            return true;
        }
        return repertoryMapper.insertSelective(repertory) == 1;
    }

    @Override
    public boolean deleteRepertoryById(Integer repertoryId) {
        if (repertoryId == null) {
            throw new NullPointerException();
        }
        return repertoryMapper.deleteByPrimaryKey(repertoryId) == 1;
    }

    @Override
    public boolean updateRepertory(Repertory repertory) {
        if (CheckUtil.allNullBeanCheck(repertory)) {
            return true;
        }
        return repertoryMapper.updateByPrimaryKeySelective(repertory) == 1;
    }
}
